package com.jt.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jt.mapper.UserMapper;
import com.jt.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Cx
 * @stage JT Of Fourth stage
 * @creat 2020-12-12 10:33
 */
@Service
public class UserServiceImpl implements UserService {

    private static Map<Integer, String> paraMap = new HashMap<>();

    static {
        paraMap.put(1, "username");
        paraMap.put(2, "phone");
        paraMap.put(3, "email");
    }

    @Autowired(required = false)
    private UserMapper userMapper;

    @Override
    public boolean checkUser(String param, Integer type) {
        String column = paraMap.get(type);
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(column, param);
        Integer count = userMapper.selectCount(queryWrapper);
        return count > 0;
    }

    @Override
    public List<User> findUserList() {
        List<User> users = userMapper.selectList(null);
        return users;
    }

}
